package pers.kw.server.login.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import pers.kw.entity.TokenInfoDto;
import pers.kw.protocol.R;
import pers.kw.server.login.dto.LoginReqDto;
import pers.kw.server.login.dto.RefreshTokenDto;
import pers.kw.server.login.service.LoginService;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    @ApiOperation(value = "登录获取token")
    @PostMapping(value = "/crm/api/get/token")
    public R<TokenInfoDto> login(@Valid @RequestBody LoginReqDto reqDto) {
        return R.ok(loginService.login(reqDto));
    }

    @ApiOperation(value = "刷新token")
    @PostMapping(value = "/crm/api/refresh/token")
    public R<TokenInfoDto> refreshToken(@Valid @RequestBody RefreshTokenDto reqDto) {
        return R.ok(loginService.refreshToken(reqDto));
    }

    @ApiOperation(value = "退出")
    @PostMapping(value = "/crm/api/sys/logout")
    public R logout() {
        loginService.logout();
        return R.ok();
    }
}
